#include "RingQueue.hpp"

void* Productor(void *args)
{
    RingQueue<int> *rq = (RingQueue<int> *)args;
    srand(time(nullptr));
    while (true)
    {
        int data = rand();
        rq->rqEqueue(data);
        std::cout << "生产了一个数据: " << data << std::endl;
        sleep(1);
    }
}
void *Consumer(void *args)
{
    RingQueue<int> *rq = (RingQueue<int> *)args;
    while (true)
    {
        sleep(1);
        int data = 0;
        rq->rqPop(&data);
        std::cout << "消费了一个数据: " << data << std::endl;
    }
}
int main()
{
    RingQueue<int> rq(1000);
    pthread_t c1, c2, c3, p1, p2;

    pthread_create(&p1, nullptr, Productor, (void *)&rq);
    pthread_create(&p2, nullptr, Productor, (void *)&rq);

    pthread_create(&c1, nullptr, Consumer, (void *)&rq);
    pthread_create(&c2, nullptr, Consumer, (void *)&rq);
    pthread_create(&c3, nullptr, Consumer, (void *)&rq);

    sleep(100);
    return 0;
}